package com.unionpay.db;

import java.util.Date;

import com.unionpay.async.AsyncTask;
import com.unionpay.async.AsyncTaskPool;
import com.unionpay.entity.QueryfromchainEntity;
import com.unionpay.mapper.QueryfromchainEntityMapper;
import com.unionpay.util.StrUtil;

/**
 * queryfromchain表操作
 * 
 * @author liuzy
 * @since 2016年4月29日
 */
public class TblQueryfromchain {
	static QueryfromchainEntityMapper mapper = Mybaties.getMapper(QueryfromchainEntityMapper.class);

	public static void save(String nodeurl, String bizid, String transactionid, String blockHash, String blockNumber, String content, String transactionIndex) {
		QueryfromchainEntity entity = new QueryfromchainEntity();
		entity.setNodeurl(nodeurl);
		entity.setBizid(bizid);
		entity.setTransactionid(transactionid);
		entity.setBlockHash(blockHash);
		entity.setBlockNumber(blockNumber);
		entity.setContent(content);
		entity.setTransactionIndex(transactionIndex);
		entity.setTime(new Date());
		mapper.insert(entity);
	}

	public static void asyncSave(String nodeurl, String bizid, String transactionid, String blockHash, String blockNumber, String content, String transactionIndex) {
		String sql = "insert into queryfromchain(`nodeurl`,`bizid`,`transactionid`, `blockHash`, `blockNumber`, `content`, `transactionIndex`, `time`) value(?,?,?,?,?,?,?,?)";
		AsyncTask asyncTask = new AsyncTask(sql, new String[] { nodeurl, bizid, transactionid, blockHash, blockNumber, content, transactionIndex, StrUtil.getDate(new Date()) });
		AsyncTaskPool.add(asyncTask);
	}
}
